package com.yanqu.road.server.cmd.activity.stronghold;

import com.yanqu.road.entity.activity.ActivityRewardResult;
import com.yanqu.road.pb.activity.StrongholdWarProto;
import com.yanqu.road.pb.cross.activity.CrossActivityProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.activity.strongholdwar.StrongholdActivityModule;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.Protocol;

@Cmd(code = Protocol.S_CROSS_STRONGHOLD_GET_RANK_REWARD_NOTIFY, desc = "跨服据点战领取奖励通知")
public class CrossStrongholdGetRewardNotifyCmd extends AbstractCommand {
	private int activityId;
	private int conditionId;
	private int myRank;
	private ActivityRewardResult rewardResult;
	private int position;
	private String unionId;
	@Override
	public boolean parseData(YanQuMessage packet) throws Exception {
		CrossActivityProto.CrossActivityGetRewardRespMsg reqMsg = CrossActivityProto.CrossActivityGetRewardRespMsg.parseFrom(packet.getBytes());
		activityId = reqMsg.getActivityId();
		conditionId = reqMsg.getConditionId();
		myRank = reqMsg.getRank();
		position = reqMsg.getPosition();
		unionId = reqMsg.getUnionId();
		return true;
	}

	@Override
	public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
		rewardResult = player.getModule(StrongholdActivityModule.class).getCrossRankReward(activityId, conditionId,  myRank,position,unionId);
	}

	@Override
	public void sendData(GamePlayer player) {
		StrongholdWarProto.StrongholdActivityGetRewardRespMsg.Builder respMsg = StrongholdWarProto.StrongholdActivityGetRewardRespMsg.newBuilder();
		respMsg.setRet(rewardResult.getRet());
		if(0 == respMsg.getRet()){
			respMsg.setReward(rewardResult.getReward());
		}
		player.sendPacket(Protocol.U_STRONGHOLD_ACTIVITY_GET_RANK_REWARD, respMsg);
	}

}
